public class YieldDemo {
//yield方法会让出cpu，但是已经处于可运行状态（Runnable）
    static class PrintTread extends Thread{
        private final String target;
        private final boolean isYield;

        public PrintTread(String target,boolean isYield){
            this.target=target;
            this.isYield=isYield;

        }
        @Override
        public void run() {
            while(true){
                System.out.println(target);
                if(isYield){
                    Thread.yield();
                }
            }


        }
    }

    public static void main(String[] args) {

        PrintTread printTread1=new PrintTread("A",true);
        PrintTread printTread2=new PrintTread("B",false);

        printTread1.start();
        printTread2.start();

    }
}
